#!/bin/sh
#PBS -N kawa-1
#PBS -l nodes=4:ppn=15
#PBS -j oe
#PBS -q low

INPUT_FILE="kawa-1"
OUTPUT_FILE=$INPUT_FILE".log"
ABAQUS_EXEC="abaqus"
ABAQUS_ENV="abaqus_v6.env"
source /public/software/profile.d/abaqus2018-env.sh

##############################################################
########## You don't need to modify the lines below ##########
##############################################################
GetNodeList()
{
np=1
while read line; do
host=$line
if [ ! -z $lasthost ]; then
if [ $host = $lasthost ]; then
np=`expr $np + 1`
else
if [ -z $mList ]; then
mList=[\'$lasthost\',$np]
else
mList=$mList,[\'$lasthost\',$np]
fi
np=1
fi
fi
lasthost=$host
done < $1
if [ -z $mList ]; then
mList=[\'$lasthost\',$np]
else
mList=$mList,[\'$lasthost\',$np]
fi
echo [$mList]
}
NODE_LIST=`GetNodeList $PBS_NODEFILE`
NPROCS=`wc -l < $PBS_NODEFILE`
cd $PBS_O_WORKDIR
#cp $ABAQUS_ENV abaqus_v6.env
cat << EOF > abaqus_v6.env
mp_host_list=$NODE_LIST
EOF
echo $ABAQUS_EXEC int j=$INPUT_FILE cpus=$NPROCS >& $OUTPUT_FILE
$ABAQUS_EXEC int j=$INPUT_FILE cpus=$NPROCS >& $OUTPUT_FILE
